<%@page import="com.xnx3.j2ee.Global" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@page import="com.xnx3.wangmarket.admin.G" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<style>
    .layui-form-item{
        clear: none!important;
    }
    .layui-btn {
        background-color: #28a44d;
    }
</style>

<jsp:include page="../iw/common/head.jsp">
    <jsp:param name="title" value="修改网站基本信息"/>
</jsp:include>

<form id="form" action="saveSite.do" method="post" class="layui-form" style="padding:20px; padding-top:35px;">
    <div class="layui-row">
        <div class="layui-form-item layui-col-xs6">
            <label class="layui-form-label">联系人姓名</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="username" autocomplete="off" placeholder="限5个汉字以内"
                       class="layui-input" value="${site.username }">
            </div>
        </div>
        <div class="layui-form-item layui-col-xs6">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-block">
                <input type="text" name="phone" lay-verify="phone" autocomplete="off" placeholder="限14个汉字以内"
                       class="layui-input" value="${site.phone }">
            </div>
        </div>
        <div class="layui-form-item layui-col-xs6">
            <label class="layui-form-label">质询热线</label>
            <div class="layui-input-block">
                <input type="text" name="hotLine" lay-verify="hotLine" autocomplete="off" placeholder="限14个汉字以内"
                       class="layui-input" value="${site.hotLine}">
            </div>
        </div>
        <div class="layui-form-item layui-col-xs6">
            <label class="layui-form-label">联系QQ</label>
            <div class="layui-input-block">
                <input type="text" name="qq" lay-verify="qq" autocomplete="off" placeholder="请输入您的QQ号，可不填"
                       class="layui-input" value="${site.qq }">
            </div>
        </div>
        <div class="layui-form-item layui-col-xs6">
            <label class="layui-form-label">公司名称</label>
            <div class="layui-input-block">
                <input type="text" name="companyName" lay-verify="companyName" autocomplete="off"
                       placeholder="请输入您的公司或团队名字，限30字以内" class="layui-input" value="${site.companyName }">
            </div>
        </div>
        <div class="layui-form-item layui-col-xs6">
            <label class="layui-form-label">企业邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="companyEmail" lay-verify="companyEmail" autocomplete="off"
                       placeholder="请输入您的公司邮箱地址，限30字以内" class="layui-input" value="${site.companyEmail}">
            </div>
        </div>

        <form id="form1" method="post" class="layui-form" enctype="multipart/form-data"
              style="padding-top:35px; margin-bottom: 10px; padding-right:35px;">
            <div class="layui-form-item layui-col-xs6">
                <label class="layui-form-label">公司logo</label>
                <div class="layui-input-block">
                    <img src='<%=basePath%>${site.logo } ' alt='' id='img' style="width: 150px;height: 50px;top: 20px;"/><br>
                </div>
            </div>
            <div class="layui-form-item layui-col-xs6">
                <label class="layui-form-label">公司logo</label>
                <div id="uploadForm" class="layui-input-block">
                    <input id="file" type="file" style="width: 50%; float:left"/>
                    <%--<button id="upload" type="button" style="width: 50%;float:left" onclick="getUpload()">上传logo</button>--%>
                </div>
                <%--<div class="layui-progress layui-progress-big">--%>
                    <%--<div class="layui-progress-bar" lay-percent="20%"></div>--%>
                <%--</div>--%>
            </div>
        </form>

        <%--<form id="form2" method="post" class="layui-form" enctype="multipart/form-data"--%>
              <%--style="padding-top:35px; margin-bottom: 10px; padding-right:35px;">--%>
            <%--<div class="layui-form-item layui-col-xs6">--%>
                <%--<label class="layui-form-label">主页轮播图</label>--%>
                <%--<div class="layui-input-block">--%>
                    <%--<img src='<%=basePath%>' alt='' id='img1' style="width: 150px;height: 50px;top: 20px;"/><br>--%>
                <%--</div>--%>
            <%--</div>--%>
            <%--<div class="layui-form-item layui-col-xs6">--%>
                <%--<label class="layui-form-label" style="margin-left: 20px">轮播图</label>--%>
                <%--<div id="uploadForm1" class="layui-input-block">--%>
                    <%--&lt;%&ndash;<input id="files" name="files" type="file" style="width: 50%; float:left"  multiple="multiple"/>&ndash;%&gt;--%>
                        <%--<input id="files" name="files" type="file" style="width: 50%; float:left"/>--%>
                        <%--<button id="upload1" type="button" style="width: 50%;float:left;" onclick="getUploadBro()">上传轮播</button>--%>
                <%--</div>--%>
            <%--</div>--%>
        <%--</form>--%>
        <div class="layui-form-item" style="float: left;width:100%;">
            <label class="layui-form-label">办公地址</label>
            <div class="layui-input-block">
            <textarea name="address" required lay-verify="address" placeholder="请输入您的公司地址"
                      class="layui-textarea">${site.address }</textarea>
            </div>
        </div>
    </div>


    <%--上传公司logo--%>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">保存修改</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>



<script type="text/javascript">

    <%--function getUploadBro() {--%>
        <%--var formData = new FormData();--%>
        <%--var files = document.getElementById("files").files;--%>
        <%--for(var i=0;i<files.length;i++){--%>
            <%--formData.append('files', $('#files')[0].files[i]);--%>
        <%--}--%>

        <%--$.ajax({--%>
            <%--url: '<%=basePath %>site/uploadBroadImage.do',--%>
            <%--type: 'POST',--%>
            <%--dataType: "json",--%>
            <%--cache: false,--%>
            <%--data: formData,--%>
            <%--processData: false,--%>
            <%--contentType: false--%>
        <%--}).success(function (res) {--%>
            <%--console.log(res)--%>
            <%--res.suss==0? layer.msg('上传成功', {shade: 0.3}):layer.msg('请选择图片', {icon:0,shade: 0.3});--%>
            <%--document.getElementById("img").src = res.data;--%>
        <%--}).fail(function (res) {--%>
            <%--layer.msg('上传失败', {shade: 0.3});--%>
        <%--});--%>
    <%--}--%>
    function getUploadBro() {
        var formData = new FormData();
        formData.append('file', $('#files')[0].files[0]);
        $.ajax({
            url: '<%=basePath %>CompanyInfoController/uploadImage.do',
            type: 'POST',
            dataType: "json",
            cache: false,
            data: formData,
            processData: false,
            contentType: false
        }).done(function (res) {
            res.result==1? layer.msg('上传成功', {shade: 0.3}):layer.msg('请选择图片', {icon:0,shade: 0.3});
            document.getElementById("img").src = res.data;
        }).fail(function (res) {
            console("失败");
        });
    }
    $('#file').change(function(){
        getUpload()
    })

    function getUpload() {
        var formData = new FormData();
        formData.append('file', $('#file')[0].files[0]);
        $.ajax({
            url: '<%=basePath %>site/uploadImage.do',
            type: 'POST',
            dataType: "json",
            cache: false,
            data: formData,
            processData: false,
            contentType: false
        }).done(function (res) {
            res.result==1? layer.msg('上传成功', {shade: 0.3}):layer.msg('请选择图片', {icon:0,shade: 0.3});
            document.getElementById("img").src = res.data;
        }).fail(function (res) {
            console("失败");
        });
    }
    try {
        //自适应弹出层大小
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.iframeAuto(index);
    } catch (err) {
    }

    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form;

        //自定义验证规则
        form.verify({
            username: function (value) {
                if (value.length > 5) {
                    return '联系人姓名不能超过5个字！';
                }
            },
            phone: function (value) {
                if (value.length == 0 || value.length > 14) {
                    return '请输入14个数字以内的联系电话';
                }
            },
            qq: function (value) {
                if (value.length == 0 || value.length > 14) {
                    return '请输入12个数字或以内的QQ号';
                }
            },
            companyName: function (value) {
                if (value.length > 30) {
                    return '请输入30个字以内的公司名字';
                }
            },
            address: function (value) {
                if (value.length > 80) {
                    return '请输入80个字以内的公司或办公所在地址';
                }
            }
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            $.showLoading('数据保存中');
            var d = $("form").serialize();
            $.post("<%=basePath %>site/savePopupSiteUpdate.do", d, function (result) {
                $.hideLoading();
                var obj = JSON.parse(result);
                if (obj.result == '1') {
                    parent.layer.msg('操作成功', {shade: 0.3});
                } else if (obj.result == '0') {
                    parent.layer.msg(obj.info, {shade: 0.3})
                } else {
                    parent.layer.msg(result, {shade: 0.3})
                }
                parent.layer.close(index);
            }, "text");

            return false;
        });

    });
</script>

</body>
</html>